package com.cy.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class Application {

    /*
     * 测试redis集群
     * */
    @Autowired
    private RedisConnectionFactory factory;

    @Autowired
    private RedisTemplate redisTemplate;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    /*
    * spring执行流程：
    * 扫描 --> 创建实例 --> 依赖注入 --> @PostConstruct(用于执行一些自定义初始化操作)
    * */
    @PostConstruct
    public void test() {
        RedisClusterConnection cluster = factory.getClusterConnection();
        for (int i = 0; i < 100; i++) {
            String k = "k"+i;
            String v = "v"+i;
            cluster.set(k.getBytes(),v.getBytes());
        }
    }
}
